package com.spotalog.server.service.rest;

import static com.spotalog.shared.service.rest.Endpoints.QueryParams.CREATED;
import static com.spotalog.shared.service.rest.Endpoints.QueryParams.CURSOR;
import static com.spotalog.shared.service.rest.Endpoints.QueryParams.KEYWORDS;
import static com.spotalog.shared.service.rest.Endpoints.QueryParams.LIMIT;
import static com.spotalog.shared.service.rest.Endpoints.Users.ENDPOINT;

import java.net.URI;
import java.util.Date;
import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.google.appengine.api.users.User;
import com.google.common.collect.Lists;
import com.spotalog.shared.service.rest.Envelope;

@Path(ENDPOINT)
public class UserResource {
	@GET
	@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
	public Envelope<User> query(@QueryParam(KEYWORDS) String keywords,
			@QueryParam(CREATED) Date created, @QueryParam(CURSOR) String cursor,
			@QueryParam(LIMIT) int limit) {
		List<User> results = Lists.newArrayList();

		return new Envelope<User>(results, results.size(), null);
	}

	@POST
	@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
	public Response create(User user) {
		return Response.created(URI.create(user.getEmail())).build();
	}

	@PUT
	@Path("{email}")
	@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
	public Response update(@PathParam("email") String email, User user) {
		return Response.ok().build();
	}

	@DELETE
	@Path("{email}")
	public Response delete(@PathParam("email") String email) {
		return Response.ok().build();
	}
}
